You can exercise an option or let it lapse using the exerciseOptions method. In IBSampleApp, you do this on the Option exercising tab:
Internally, the sample application will retrieve all open positions of the selected account and extract only the option (OPT) contracts for ease of use. You can override the system's natural action using the override parameter of the exerciseOptions method. This results in the exercise of options that are “out-of-the-money.”